$(document).ready(function() {

    queryAllCategory();

    
});

$(document).on('click', '#serach', function() {

    var keywords=$("input[name='serach-input']").val();

    window.location.href = 'search.html?keywords='+keywords;

});


var queryAllCategory = function () {

    $.ajax({
        url: "http://localhost:8002/category/generateCategoryTree",
        type: "POST",
        async: true,
        dataType: "json",
        success: function (data) {


            if (data.code===201) {

                $.each(data.data,function (index, value) {

                    var category = value.categoryDetails;



                    $("#nav").append(

                        //这层遍历最外层的大类菜单

                        "<li>" +
                        "<a href=\"\">"+value.categoryName+"</a>" +
                        "<div class=\"pop\">\n" +
                        "<div class=\"left fl\">\n" +
                        "<div class="+value.categoryName+">" +


                        "</div>"+
                        "</div>"+
                        "<div class=\"clear\"></div>" +
                        "</div>" +
                        "</li>"
                    )


                    $.each(category,function (index1, value1) {

                        //这层遍历每个分类中的小类别

                        $("."+value.categoryName+"").append(

                            "<div class=\"xuangou_left fl\" >" +
                            "<a href=\"\">" +
                            "<div class=\"img fl\"><img src="+value1.listImage+" alt=\"\" width='40px'></div>" +
                            "<span class=\"fl\">"+value1.detailName+"</span>" +
                            "<div class=\"clear\"></div>" +
                            "</a>" +
                            "</div>" +
                            "<div class=\"xuangou_right fr\"><a href='./goods/phone/mi9.html' target=\"_blank\">选购</a></div>" +
                            "<div class=\"clear\"></div>"
                        )
                    })


                })



            }else{
                layer.msg("加载失败!");
            }
        },
        error: function () {
            layer.msg("加载失败!");
        }


    })
}





